//package MEET.src.View;
//
//import MEET.src.code.Meeting;
//import com.toedter.calendar.JDateChooser;
//
//import javax.swing.*;
//import javax.swing.table.DefaultTableModel;
//import java.awt.*;
//import java.text.SimpleDateFormat;
//import java.util.List;
//
//public class CalendarPanel extends JPanel {
//    private JDateChooser dateChooser; // 改用JDateChooser实现下拉日历
//    private JTable meetingTable;
//
//    public CalendarPanel(List<Meeting> meetings) {
//        setLayout(new BorderLayout(5, 5));
//        setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
//
//        // 创建查询条件面板
//        JPanel searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 5));
//        searchPanel.setBackground(new Color(240, 240, 240));
//
//        // 创建日期选择器
//        dateChooser = new JDateChooser();
//        dateChooser.setDateFormatString("yyyy-MM-dd");
//        dateChooser.getCalendarButton().setText("▼"); // 设置下拉按钮样式
//
//        JButton btnSearch = new JButton("查询");
//        btnSearch.setBackground(new Color(0, 125, 153));
//        btnSearch.setForeground(Color.WHITE);
//
//        searchPanel.add(new JLabel("选择日期:"));
//        searchPanel.add(dateChooser);
//        searchPanel.add(btnSearch);
//
//        // 创建会议表格
//        String[] columns = {"会议号", "会议名称", "起始时间", "结束时间", "地点", "状态"};
//        DefaultTableModel model = new DefaultTableModel(columns, 0) {
//            @Override
//            public boolean isCellEditable(int row, int column) {
//                return false; // 表格不可编辑
//            }
//        };
//
//        meetingTable = new JTable(model);
//        meetingTable.setRowHeight(30);
//        meetingTable.getTableHeader().setFont(new Font("微软雅黑", Font.BOLD, 12));
//
//        // 布局
//        add(searchPanel, BorderLayout.NORTH);
//        add(new JScrollPane(meetingTable), BorderLayout.CENTER);
//
//        // 加载会议数据
//        loadMeetings(meetings);
//    }
//
//    private void loadMeetings(List<Meeting> meetings) {
//        DefaultTableModel model = (DefaultTableModel) meetingTable.getModel();
//        model.setRowCount(0);
//
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
//
//        for (Meeting meeting : meetings) {
//            model.addRow(new Object[]{
//                    meeting.getMID(),
//                    meeting.getMname(),
//                    sdf.format(meeting.getMstarttime()),
//                    sdf.format(meeting.getMendtime()),
//                    meeting.getPlace() + " " + meeting.getRoom(),
//                    meeting.getStatus()
//            });
//        }
//    }
//
//    private class JDateChooser {
//    }
//}
package MEET.src.View;

import MEET.src.code.Meeting;
import com.toedter.calendar.JDateChooser;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.List;

public class CalendarPanel extends JPanel {
    private JDateChooser dateChooser; // 使用正确的 JDateChooser 类
    private JTable meetingTable;

    public CalendarPanel(List<Meeting> meetings) {
        setLayout(new BorderLayout(5, 5));
        setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

        // 创建查询条件面板
        JPanel searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 5));
        searchPanel.setBackground(new Color(240, 240, 240));

        // 创建日期选择器
        dateChooser = new JDateChooser() {
            @Override
            public void setDateFormatString(String dateFormatString) {
                super.setDateFormatString(dateFormatString);
            }
        };
        dateChooser.setDateFormatString("yyyy-MM-dd");
        dateChooser.getCalendarButton().setText("▼"); // 设置下拉按钮样式

        JButton btnSearch = new JButton("查询");
        btnSearch.setBackground(new Color(0, 125, 153));
        btnSearch.setForeground(Color.WHITE);

        searchPanel.add(new JLabel("选择日期:"));
        searchPanel.add(dateChooser);
        searchPanel.add(btnSearch);

        // 创建会议表格
        String[] columns = {"会议号", "会议名称", "起始时间", "结束时间", "地点", "状态"};
        DefaultTableModel model = new DefaultTableModel(columns, 0) {
            @Override
            public boolean isCellEditable(int row, int column) {
                return false; // 表格不可编辑
            }
        };

        meetingTable = new JTable(model);
        meetingTable.setRowHeight(30);
        meetingTable.getTableHeader().setFont(new Font("微软雅黑", Font.BOLD, 12));

        // 布局
        add(searchPanel, BorderLayout.NORTH);
        add(new JScrollPane(meetingTable), BorderLayout.CENTER);

        // 加载会议数据
        loadMeetings(meetings);
    }

    private void loadMeetings(List<Meeting> meetings) {
        DefaultTableModel model = (DefaultTableModel) meetingTable.getModel();
        model.setRowCount(0);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

        for (Meeting meeting : meetings) {
            model.addRow(new Object[]{
                    meeting.getMID(),
                    meeting.getMname(),
                    sdf.format(meeting.getMstarttime()),
                    sdf.format(meeting.getMendtime()),
                    meeting.getPlace() + " " + meeting.getRoom(),
                    meeting.getStatus()
            });
        }
    }
}